package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CarInfo;
import cn.wolfcode.crm.query.CarInfoQueryObject;
import cn.wolfcode.crm.service.ICarInfoService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import com.alibaba.fastjson.JSON;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("carInfo")
public class CarInfoController {
    @Autowired
    private ICarInfoService service;
    @RequestMapping("")
    private String index(){
        return "carInfo/list";
    }


    @RequestMapping("list")
    @ResponseBody
    @RequiresPermissions("carInfo:list")
    @PermissionName("车详细信息列表")
    private PageResult list(CarInfoQueryObject qo){
        System.out.println(JSON.toJSONString(service.query(qo)));
        return service.query(qo);
    }
    @RequestMapping("edit")
    @ResponseBody
    @RequiresPermissions("carInfo:edit")
    @PermissionName("车详细信息更新")
    private JsonResult edit(CarInfo ci){
        JsonResult result = new JsonResult();
        try {
            service.update(ci);
        } catch (Exception e) {
            e.printStackTrace();
            result.setMsg("编辑失败");

        }
        return result;
    }
}
